package unit2.creater;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

import unit2.csvPaser.EnterAnswerQuestionEntryParser;
import unit2.question.EnterAnswerQuestion;
import unit2.question.Question;

/**
 * 
 * @author Nick
 *
 */

public class CreaterTest {
	 private final String fileOfYesNoQuestions="yesnoquestion.csv";
	 private final String fileOfChooseAnswerQuestions="choosequestion.csv";
	 private final String fileOfEnterAnswerQuestions="enterquestion.csv";

	 public ArrayList<Question> createTest(int countOfYesNoQuestions, int countOfChooseAnswerQuestions, int countOfEnterAnswerQuestions){
		ArrayList<Question> questions = new ArrayList<Question>();
		 if(countOfYesNoQuestions!=0){
			 Question[] array = createQuestionsSomeType(this.fileOfYesNoQuestions);
			 for(int i=0; i<countOfYesNoQuestions; i++){
				 questions.add(i, array[i]);
			 }
		 }
		 
		if(countOfChooseAnswerQuestions!=0){
			 Question[] array =createQuestionsSomeType(this.fileOfChooseAnswerQuestions);
			 for(int i=0; i<countOfChooseAnswerQuestions; i++){
				 questions.add(i+countOfYesNoQuestions, array[i]);
			 }
		}

		if(countOfEnterAnswerQuestions!=0){
			Question[] array = createQuestionsSomeType(this.fileOfEnterAnswerQuestions);
			 for(int i=0; i<countOfEnterAnswerQuestions; i++){
				 questions.add(i+countOfYesNoQuestions+countOfChooseAnswerQuestions,array[i]);
			 }
		}
		
		Collections.shuffle(questions);
		
		
		return questions;
	 }
	 
	 private Question[] createQuestionsSomeType(String adress){
		 EnterAnswerQuestionEntryParser temp= new EnterAnswerQuestionEntryParser();
		 List <EnterAnswerQuestion> listOfQuestion= temp.readQuestions(adress);
		 Question[] array= listOfQuestion.toArray(new Question[listOfQuestion.size()]);
		 return array;		 
	 }
	 	 
	
}

